/**
 * 手打牌（碰牌提示）
 * @param card_input   碰牌者
 * @param card_number  牌号
 */
function hand_peng( card_input , card_number ){
    var self = PL_Room_Play;
    //界面画过的按钮
    if( self.BTN_CLOSE == null ) {
        self.BTN_CLOSE = cc.Sprite.create(res.Room_CLOSE);
        self.BTN_CLOSE.x = self.realy_size.width / 2  + 150;
        self.BTN_CLOSE.y = self.realy_size.height / 2 + 20;
        self.addChild(self.BTN_CLOSE);
        var temp_listen = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: function (touch, event) {
                var target = event.getCurrentTarget();
                var locationInNode = target.convertToNodeSpace(touch.getLocation());
                var s = target.getContentSize();
                var rect = cc.rect(0, 0, s.width, s.height);
                if (cc.rectContainsPoint(rect, locationInNode)) {
                    delete_all();
                    PB_WS.send("w:" + PB_USER_UID + ":" + ROOM_ID + ":" + card_number + ":" + card_input);
                }
            },
        });
        cc.eventManager.addListener(temp_listen, self.BTN_CLOSE);
        GAME_NOW_BTN_C++;
    }
    //界面画出碰的按钮
    self.BTN_PENG     = cc.Sprite.create( res.Room_PENG );
    self.BTN_PENG.x   = (self.realy_size.width / 2  + 150) - (GAME_NOW_BTN_C * 140 );
    self.BTN_PENG.y   = self.realy_size.height / 2 + 20;
    self.addChild( self.BTN_PENG );
    var temp_listen = cc.EventListener.create({
        event:cc.EventListener.TOUCH_ONE_BY_ONE,
        swallowTouches:true,
        onTouchBegan:function(touch,event){
            var target = event.getCurrentTarget();
            var locationInNode = target.convertToNodeSpace(touch.getLocation());
            var s      = target.getContentSize();
            var rect   = cc.rect(0, 0, s.width, s.height);
            if (cc.rectContainsPoint(rect, locationInNode)) {
                delete_all();
                for( var i = self.PPP_pai.length - 1; i >= 1 ; i-- ) {//清楚手牌中的2个牌
                    if( self.PPP_pai[i].paihao == card_number ){
                        self.removeChild( self.PPP_pai[i] );
                        DUN_PS[self.PPP_pai[i]-1]--;
                    }
                }
                PB_WS.send("q:" + PB_USER_UID + ":" + ROOM_ID + ":" + card_number + ":" + card_input);
                draw_play_paireset();//理牌
            }
        },
    });
    cc.eventManager.addListener( temp_listen ,  self.BTN_PENG );
    GAME_NOW_BTN_C++;
}

function hand_chi( card_number , input_uid , chi_pai ) {
    var self = PL_Room_Play;
    //绘制过按钮以及事件
    if( self.BTN_CLOSE == null ){
        self.BTN_CLOSE    = cc.Sprite.create( res.Room_CLOSE );
        self.BTN_CLOSE.x  = self.realy_size.width / 2  + 150;
        self.BTN_CLOSE.y  = self.realy_size.height / 2 + 20;
        self.addChild( self.BTN_CLOSE );
        var temp_listen = cc.EventListener.create({
            event:cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches:true,
            onTouchBegan:function(touch,event){
                var target = event.getCurrentTarget();
                var locationInNode = target.convertToNodeSpace(touch.getLocation());
                var s      = target.getContentSize();
                var rect   = cc.rect(0, 0, s.width, s.height);
                if (cc.rectContainsPoint(rect, locationInNode)) {
                    delete_all();
                    PB_WS.send("e:" + PB_USER_UID + ":" + ROOM_ID + ":" + card_number + ":" + input_uid);
                }
            },
        });
        cc.eventManager.addListener( temp_listen ,  self.BTN_CLOSE );
        GAME_NOW_BTN_C++;
    }
    //绘制吃牌按钮以及事件
    self.BTN_CHI     = cc.Sprite.create( res.Room_CHI );
    self.BTN_CHI.x   = (self.realy_size.width / 2  + 150) - (GAME_NOW_BTN_C * 140 );
    self.BTN_CHI.y   = self.realy_size.height / 2 + 20;
    self.addChild( self.BTN_CHI );
    var temp_listen = cc.EventListener.create({
        event:cc.EventListener.TOUCH_ONE_BY_ONE,
        swallowTouches:true,
        onTouchBegan:function(touch,event){
            var target = event.getCurrentTarget();
            var locationInNode = target.convertToNodeSpace(touch.getLocation());
            var s      = target.getContentSize();
            var rect   = cc.rect(0, 0, s.width, s.height);
            if (cc.rectContainsPoint(rect, locationInNode)) {
                //当前是否有人能碰牌？ & 当前能碰牌的人是不是跟我是同一个人？是同一个人的话，是允许我自己吃的 - 条件：没人能碰 or  碰牌人跟吃牌人都是我自己
                if( GAME_IS_PENG == 0 || GAME_PENG_UID == GAME_CHI_UID ) {
                    //下移关闭按钮
                    PL_Room_Play.BTN_CLOSE.runAction( cc.MoveTo.create( 0.3 , cc.p( PL_Room_Play.realy_size.width - 300 , 200 ) ) );
                    //消除碰按钮跟吃按钮
                    self.removeChild(self.BTN_CHI);
                    self.removeChild(self.BTN_PENG);
                    GAME_NOW_BTN_C = 0;
                    play_eat_pai(chi_pai, card_number,input_uid);
                }
            }
        },
    });
    cc.eventManager.addListener( temp_listen ,  self.BTN_CHI );
}